package org.theSeed.rbacBaseCommon.pojo.sysEnum;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

/**
 * 菜单枚举
 */
public enum ResourceTypeEnum {
    DIR("D","目录"),
    MENU("M","菜单"),
    BTN("B","按钮"),
    ;
    ResourceTypeEnum(String code, String describStr) {
        this.code = code;
        this.describStr = describStr;
    }

    /**
     * 编码
     */
    @Getter
    private String code;

    /**
     * 描述字符
     */
    @Getter
    private String describStr;

    /**
     * 获取实例
     * @param code
     * @return
     */
    public static ResourceTypeEnum getInstance(Integer code){
        if (ObjectUtil.isNull(code)){
            return null;
        }

        for (ResourceTypeEnum item : values()) {
            if (item.code.equals(code))
                return item;
        }
        return null;
    }

    /**
     * 是否为菜单
     * @param resourceType
     * @return
     */
    public static boolean isMenu(String resourceType){
        if (DIR.code.equals(resourceType) || MENU.code.equals(resourceType)){
            return true;
        }else {
            return false;
        }
    }
}
